//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


namespace Shp.Runtime.Contract
{
    using System;
    using System.Runtime.Serialization;
    using System.Globalization;
    using System.Threading;

    [DataContract, Serializable]
    public class Upn
    {
        public Upn(string upn)
        {
            _userName = upn.Split('@')[0];
            _domain = upn.Split('@')[1];
        }

        public Upn(string userName, string domain)
        {
            _userName = userName;
            _domain = domain;
        }

        private string _userName;
        [DataMember]
        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        private string _domain;
        [DataMember]
        public string Domain
        {
            get { return _domain; }
            set { _domain = value; }
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{0}@{1}", _userName, _domain);
        }

        static public Upn Current
        {
            get
            {
                Upn upn = new Upn(Thread.CurrentPrincipal.Identity.Name);
                return upn;
            }
        }
    }
}
